<template>
  <el-dialog
      title="验货"
      width="450px"
      @close="cancel"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="form" :rules="rules" ref="Form" label-width="120px">
      <el-form-item label="第三方单号:" prop="otherNumber">
        <el-input v-model.trim="form.otherNumber"/>
      </el-form-item>
      <el-form-item label="快递公司" prop="com">
        <el-select v-model="form.com" placeholder="请选择">
          <el-option
              v-for="item in expressCode"
              :key="item.index"
              :label="item.name"
              :value="item.code">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <submit-button ref="Submit" @submit="submit"/>
    </div>
  </el-dialog>
</template>

<script>
  import {expressCode} from '@/utils/expressCode'
  import {resetForm} from "@/utils/common";
  import {examineApi} from "@/api/order";

  export default {
    name: "Check",
    data() {
      return {
        visible: false,
        form: {
          expressOrderId: null,
          otherNumber: '',
          com: ''
        },
        rules: {
          otherNumber: {required: true, message: '请输入第三方单号', trigger: 'blur'},
          com: {required: true, message: '请选择快递公司', trigger: 'change'}
        }
      }
    },
    computed: {
      expressCode() {
        return expressCode
      }
    },
    methods: {
      submit() {
        this.$refs['Form'].validate((valid) => {
          if (!valid) return false;
          let data = {...this.form};
          this.$refs.Submit.start();
          examineApi(data).then(() => {
            this.$refs.Submit.stop();
            this.$emit('update');
            this.cancel()
          }).catch(() => {
            this.$refs.Submit.stop();
          })
        });
      },
      cancel() {
        resetForm(this)
      }
    }
  }
</script>
